package com.ttai.presenter.activity;

import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

import com.google.gson.JsonObject;
import com.ttai.model.dao.DBHelper;
import com.ttai.model.net.ResponseInfo;
import com.ttai.presenter.base.BasePresenter;
import com.ttai.ui.activity.AddAcount;
import com.ttai.ui.activity.EnterPage;
import com.ttai.ui.activity.Register;
import com.ttai.ui.activity.SetMiyao;

import retrofit2.Call;

public class SetMiYaoPresenter extends BasePresenter{
    SetMiyao setMiyao;
    public String phonenumber;
    private String value;

    public SetMiYaoPresenter(SetMiyao setMiyao) {
        this.setMiyao = setMiyao;
    }

    @Override
    protected void showError(String message) {

    }

    @Override
    protected void parseJson(JsonObject json) {

    }

    public String getValue() {
        if (HomePresrenter.myPhone==null || HomePresrenter.myPhone.isEmpty()){
            if(Register.phonenumber==null || Register.phonenumber.isEmpty()){
                phonenumber = EnterPage.enterphonenumber;
            }else{
                phonenumber =Register.phonenumber;
            }
        }else {
            phonenumber =HomePresrenter.myPhone;
        }
        DBHelper dbHelper = DBHelper.getInstance(setMiyao);
        SQLiteDatabase sqLiteDatabase=dbHelper.getWritableDatabase();
        Cursor cursor=sqLiteDatabase.query("tipacount", new String[]{"tip"}, "phone= '"+phonenumber+"'", null,null, null, null);
        while (cursor.moveToNext()){
            value =cursor.getString(0);
        }
        cursor.close();
        return value;
    }

//    public void insertDB() {
//        DBHelper dbHelper = DBHelper.getInstance(setMiyao);
//        SQLiteDatabase db=dbHelper.getWritableDatabase();
//        ContentValues values=new ContentValues();
//        values.put("phone",phonenumber);
//        values.put("acountname", AddAcount.acountName);
//        values.put("acounttip", setMiyao.miYaoTip);
//        ((SQLiteDatabase) db).insert("newacount",null,values);
//        values.clear();
//    }
    public void encrypt(String token,String accountName,String account,String password){
        Call<ResponseInfo> acountAdd = responseInfoApi.acountadd(token, accountName, account, password);
        acountAdd.enqueue(new CallBackAdapter());
    }

    public void setKey(String token,String key){
        Call<ResponseInfo> seyKeyInfo = responseInfoApi.setkey(token,key);
        seyKeyInfo.enqueue(new CallBackAdapter());
    }
    public void setKetTip(String token,String keyTip){
        Call<ResponseInfo> seyKeyTipInfo = responseInfoApi.setkeytip(token,keyTip);
        seyKeyTipInfo.enqueue(new CallBackAdapter());
    }
}
